﻿using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using FluentValidation.Mvc;
using Portal.Presentation.Controllers;

namespace Portal.Presentation
{
	public class MvcApplication : System.Web.HttpApplication
	{
		protected void Application_Start()
		{
			LoggerConfig.Initialize();
			DependencyInjectionContainer.Resolve();
			AutomapperConfig.Configure();
			AreaRegistration.RegisterAllAreas();
			FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
			RouteConfig.RegisterRoutes(RouteTable.Routes);
			BundleConfig.RegisterBundles(BundleTable.Bundles);

			FluentValidationModelValidatorProvider.Configure();
		}

		protected void Application_Error(object sender, EventArgs e)
		{
			var ex = Server.GetLastError();
			var httpContext = ((MvcApplication)sender).Context;
			ApplicationError.Raise(httpContext, ex);
		} 
	}
}